<template>
  <div class="users">
    <el-input v-model="search" placeholder="请输入项目名称" prefix-icon="el-icon-search" class="inp"></el-input>
    <el-button @click="goSearch" type="primary" size="medium" icon="el-icon-search">搜索</el-button>
    <el-dropdown split-button type="primary" @click="handleClick" @command="handleCommand">管理员 &nbsp;&nbsp; {{ name }}
      <el-dropdown-menu slot="dropdown">
        <el-dropdown-item command="n">退出系统</el-dropdown-item>
      </el-dropdown-menu>
    </el-dropdown>
  </div>
</template>

<script>
// 管理员显示
export default {
  name: 'userIndex',
  data () {
    return {
      search: ''
    }
  },
  props: {
    // 确保哪个页面在搜索
    show: {
      type: Number
    },
    newSearch: {
      type: String
    }
  },
  computed: {
    name () {
      return this.$store.getters.name
    }
  },
  created () {
    if (this.newSearch !== null && this.newSearch !== '') {
      this.search = this.newSearch
    }
  },
  methods: {
    goSearch () {
      if (this.search !== null) {
        this.$store.commit('zbUn/setSearchInfo', { search: this.search, show: this.show })
        this.$router.go()
      }
    },
    handleClick () {

    },
    handleCommand () {
      this.$store.dispatch('user/logout')
      this.$router.replace('/login')
    }
  }
}
</script>

<style lang="less" scoped>
.users {
  margin-top: 2%;
  width: 100%;
  margin-bottom: 2%;
  .inp {
    width: 50%;
  }
  .el-dropdown {
    margin-left: 20%;
  }
}
</style>
